using System;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;

/// <summary>
/// Author:  Joe Morel
/// Microsoft Corporation (c) 2006
/// All rights reserved.
/// 
/// This class describes webservice code that enables a user to add and query back on tags that are stored on a
/// SQL Server on http://www.msmoderators.com
/// </summary>

[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class Service : System.Web.Services.WebService
{
    public Service () {

        //Uncomment the following line if using designed components 
        //InitializeComponent();
        tagging = new Tagging();
        auth = new Authentication();
        snip = new Snippets();
    }
    private Tagging tagging;
    private Authentication auth;
    private Snippets snip;

    [WebMethod]
    public string[] GetTagsForThread(int ThreadID, string token)
    {
        if (auth.ValidateToken(token))
            return tagging.GetTagsForThread(ThreadID);
        else
            return null;
    }

    [WebMethod]
    public void TagThread(int ThreadID, string tag, string subject, string token)
    {
        if (auth.ValidateToken(token))
            tagging.AddTag(ThreadID, tag, subject);
    }

    [WebMethod]
    public int[] GetThreadsbyTag(string tag, string token)
    {
        if (auth.ValidateToken(token))
            return tagging.GetThreadIDsbyTag(tag);
        else
            return null;
    }

    [WebMethod]
    public string GetSubjectforThreadID(int ThreadID, string token)
    {
        if (auth.ValidateToken(token))
            return tagging.GetSubjectbyThreadID(ThreadID);
        else
            return null;
    }

    [WebMethod]
    public int CreateNewUser(string username, string password, string secret)
    {
        return auth.CreateNewUser(username, password, secret);
    }

    [WebMethod]
    public string Login(string username, string password)
    {
        return auth.Login(username, password);
    }

    [WebMethod]
    public string[] GetSnippetList(string token)
    {
        if (auth.ValidateToken(token))
            return snip.GetSnippetList(token);
        else
            return null;
    }

    [WebMethod]
    public string GetSnippet(string title, string token)
    {
        if (auth.ValidateToken(token))
            return snip.GetSnippet(title, token);
        else
            return null;
    }

    [WebMethod]
    public bool EditSnippet(string title, string newSubject, string token)
    {
        if (auth.ValidateToken(token))
            return snip.EditSnippet(title, newSubject, token);
        else
            return false;
    }

    [WebMethod]
    public bool AddSnippet(string title, string subject, string token)
    {
        if (auth.ValidateToken(token))
            return snip.AddSnippet(title, subject, token);
        else
            return false;
    }

    [WebMethod]
    public bool DeleteSnippet(string title, string token)
    {
        if (auth.ValidateToken(token))
            return snip.DeleteSnippet(title, token);
        else
            return false;
    }

    [WebMethod]
    public string[] GetTopTags(string token)
    {
        if (auth.ValidateToken(token))
            return tagging.GetTopTags();
        else
            return null;
    }
}
